package com.axonactive.yolo.dto;

import java.util.Date;

import org.apache.log4j.Logger;

import com.axonactive.yolo.domain.Task;
import com.axonactive.yolo.domain.TaskUserId;
import com.axonactive.yolo.service.internal.FlightRequesterService;
import com.axonactive.yolo.util.CONSTANTS;
import com.axonactive.yolo.util.Utils;

public class Parameters {

	private static final Logger LOGGER = Logger.getLogger(Parameters.class);

	String taskName;
	String fromLocation;
	String toLocation;
	String fromAirport;
	String toAirport;
	String fromCountry;
	String toCountry;
	String outBound;
	String inBound = "";
	Date departDate;
	Date returnDate;
	String maxPrice;
	String typeOfTrip;
	String numAdult;
	String numChild;
	String numInfant;
	int numStop;
	String flexibleDays;
	String airlines;
	String airlineNames;
	String cabinClass;
	String currencyCode;
	String airlinesFilterMode;
	String functionType;

	/**
	 * @return the departDate
	 */
	public Date getDepartDate() {
		return departDate;
	}

	/**
	 * @param departDate
	 *            the departDate to set
	 */
	public void setDepartDate(Date departDate) {
		this.departDate = departDate;
	}

	/**
	 * @return the returnDate
	 */
	public Date getReturnDate() {
		return returnDate;
	}

	/**
	 * @param returnDate
	 *            the returnDate to set
	 */
	public void setReturnDate(Date returnDate) {
		this.returnDate = returnDate;
	}

	public String getCurrencyCode() {
		return currencyCode;
	}

	public void setCurrencyCode(String currencyCode) {
		this.currencyCode = currencyCode;
	}

	public String getCabinClass() {
		return cabinClass;
	}

	public void setCabinClass(String cabinClass) {
		this.cabinClass = cabinClass;
	}

	public String getAirlineNames() {
		return airlineNames;
	}

	public void setAirlineNames(String airlineNames) {
		this.airlineNames = airlineNames;
	}

	public String getFromAirport() {
		return fromAirport;
	}

	public void setFromAirport(String fromAirport) {
		this.fromAirport = fromAirport;
	}

	public String getToAirport() {
		return toAirport;
	}

	public void setToAirport(String toAirport) {
		this.toAirport = toAirport;
	}

	public String getFromCountry() {
		return fromCountry;
	}

	public void setFromCountry(String fromCountry) {
		this.fromCountry = fromCountry;
	}

	public String getToCountry() {
		return toCountry;
	}

	public void setToCountry(String toCountry) {
		this.toCountry = toCountry;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	public String getFlexibleDays() {
		return flexibleDays;
	}

	public void setFlexibleDays(String flexibleDays) {
		this.flexibleDays = flexibleDays;
	}

	public String getAirlines() {
		return airlines;
	}

	public void setAirlines(String airlines) {
		this.airlines = airlines;
	}

	public String getFromLocation() {
		return fromLocation;
	}

	public void setFromLocation(String fromLocation) {
		this.fromLocation = fromLocation;
	}

	public String getToLocation() {
		return toLocation;
	}

	public void setToLocation(String toLocation) {
		this.toLocation = toLocation;
	}

	public String getOutBound() {
		return outBound;
	}

	public void setOutBound(String outBound) {
		this.outBound = outBound;
	}

	public String getInBound() {
		return inBound;
	}

	public void setInBound(String inBound) {
		this.inBound = inBound;
	}

	public String getTypeOfTrip() {
		return typeOfTrip;
	}

	public void setTypeOfTrip(String typeOfTrip) {
		this.typeOfTrip = typeOfTrip;
	}

	public String getNumAdult() {
		return numAdult;
	}

	public void setNumAdult(String numAdult) {
		this.numAdult = numAdult;
	}

	public String getNumChild() {
		return numChild;
	}

	public void setNumChild(String numChild) {
		this.numChild = numChild;
	}

	public String getNumInfant() {
		return numInfant;
	}

	public void setNumInfant(String numInfant) {
		this.numInfant = numInfant;
	}

	public String getMaxPrice() {
		return maxPrice;
	}

	public void setMaxPrice(String maxPrice) {
		this.maxPrice = maxPrice;
	}

	public int getNumStop() {
		return numStop;
	}

	public void setNumStop(int numStop) {
		this.numStop = numStop;
	}

	public String getAirlinesFilterMode() {
		return airlinesFilterMode;
	}

	public void setAirlinesFilterMode(String airlinesFilterMode) {
		this.airlinesFilterMode = airlinesFilterMode;
	}

	public String getFunctionType() {
		return functionType;
	}

	public void setFunctionType(String functionType) {
		this.functionType = functionType;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final double prime = 31;
		double result = 1;
		result = prime * result + ((airlineNames == null) ? 0 : airlineNames.hashCode());
		result = prime * result + ((airlines == null) ? 0 : airlines.hashCode());
		result = prime * result + ((cabinClass == null) ? 0 : cabinClass.hashCode());
		result = prime * result + ((flexibleDays == null) ? 0 : flexibleDays.hashCode());
		result = prime * result + ((fromAirport == null) ? 0 : fromAirport.hashCode());
		result = prime * result + ((fromCountry == null) ? 0 : fromCountry.hashCode());
		result = prime * result + ((fromLocation == null) ? 0 : fromLocation.hashCode());
		result = prime * result + ((inBound == null) ? 0 : inBound.hashCode());
		result = prime * result + ((maxPrice == null) ? 0 : maxPrice.hashCode());
		result = prime * result + ((numAdult == null) ? 0 : numAdult.hashCode());
		result = prime * result + ((numChild == null) ? 0 : numChild.hashCode());
		result = prime * result + ((numInfant == null) ? 0 : numInfant.hashCode());
		result = prime * result + numStop;
		result = prime * result + ((outBound == null) ? 0 : outBound.hashCode());
		result = prime * result + ((taskName == null) ? 0 : taskName.hashCode());
		result = prime * result + ((toAirport == null) ? 0 : toAirport.hashCode());
		result = prime * result + ((toCountry == null) ? 0 : toCountry.hashCode());
		result = prime * result + ((toLocation == null) ? 0 : toLocation.hashCode());
		result = prime * result + ((typeOfTrip == null) ? 0 : typeOfTrip.hashCode());
		return (int) result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Parameters) {
			Parameters par = (Parameters) obj;
			if (this.fromLocation.equals(par.fromLocation) && this.toLocation.equals(par.toLocation) && this.outBound.equals(par.outBound) && this.cabinClass.equals(par.cabinClass) && this.numAdult.equals(par.numAdult) && this.numChild.equals(par.numChild) && this.numInfant.equals(par.numInfant) && (this.numStop == par.numStop) && this.typeOfTrip.equals(par.typeOfTrip) && this.inBound.equals(par.inBound)) {
				return true;
			}
		}
		return false;
	}

	public static Parameters getParamFromTask(Task task) {
		Parameters param = new Parameters();
		param.setTypeOfTrip(task.getTypeOfTrip());
		param.setFromLocation(task.getFromCode());
		param.setToLocation(task.getToCode());
		param.setDepartDate(task.getDepartDate());
		param.setReturnDate(task.getReturnDate());
		String outBound = Utils.SDF.format(task.getDepartDate());
		param.setOutBound(outBound);
		try {
			String inBound = Utils.SDF.format(task.getReturnDate());
			param.setInBound(inBound);
		} catch (Exception e) {
			param.setInBound("");
		}
		param.setNumAdult("1");
		param.setNumChild("0");
		param.setNumInfant("0");
		param.setCabinClass(Utils.convertCabinClass(task.getCabinClass()));

		return param;
	}
}
